<template>
  <section>
    <van-sticky>
      <PageHeader title="推荐记录"/>
    </van-sticky>

    <van-list
      class="mt10"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="requestData">
      <div class="flex flex-row flex-center bg-color-white mb10 pd10 member-item"
           v-for="(item, index) in dataList"
           :key="index">
        <div class="flex flex-row flex-center">
          <img :src="item.user.avatar_url ? item.user.avatar_url : STATIC_BASE_URL + 'images/mp/gender.png'" class="avatar" />
        </div>

        <div class="flex flex-col flex-1 pl10 pr10">
          <div class="flex flex-row flex-left font-big">{{item.user.nick}}</div>
          <div class="flex flex-row flex-left font-common color-gray-dark">注册时间：{{item.user.register_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
          <div class="flex flex-row flex-left font-common color-gray-dark">最后登录：{{item.user.last_login_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
          <div class="flex flex-row">
            <div class="flex flex-row flex-left flex-1 font-common color-gray-dark"><span class="color-red">{{item.user.matchmaker_level == 1 ? '直属' : '间接'}}粉丝</span></div>
            <div class="flex flex-row flex-left flex-1 font-common color-gray-dark">累计消费：<span class="color-red">{{item.expend_amount}}</span>元</div>
          </div>
        </div>
      </div>
    </van-list>

  </section>
</template>

<script>
import PageHeader from "../componets/PageHeader";
import {BASE_STATIC_URL, matchmakerRecommendUri} from "../../common/api";

export default {
  components: {
    PageHeader
  },
  data() {
    return {
      STATIC_BASE_URL: BASE_STATIC_URL,
      currentPage: 1,
      lastPage: 0,
      total: 0,
      pageSize: 10,
      loading: false,
      finished: false,
      dataList: []
    }
  },
  methods: {
    requestData() {
      const that = this;
      this.loading = true;
      const url = matchmakerRecommendUri + '?page_size=' + that.pageSize + '&page=' + that.currentPage + '&user_id=' + this.$route.params.userId;
      this.$http.get(url).then(response => {
        let {code, msg, data} = response.body
        if (code != 0) {
          that.$toast.fail(msg);
        } else {
          that.loading = false;
          if (that.currentPage >= data.last_page) {
            that.finished = true;
          }
          that.currentPage = that.currentPage + 1;
          for (let i = 0; i < data.data.length; i++) {
            that.dataList.push(data.data[i]);
          }
          that.total = data.total;
          that.lastPage = data.last_page;
        }
      }, response => {
        // error callback
      })
    }
  },
  mounted: function () {

  }
}
</script>

<style scoped>

</style>
